"""
#!/usr/bin/python3
# coding:utf-8            
#
# Copyright (C) 2024 - 2024 Jasonakeke， Inc. All Rights Reserved 
# @Desc	   ：
# @Time    : 2024/11/3 22:24
# @Author  : Code_By_Jasonakeke
# @Email   : 2284037977@qq.com
# @File    : output.py
# @IDE     : PyCharm
"""
from json import dumps
from flask import current_app, make_response
from flask_restful.utils import PY3


def output_json(data, code, headers = None):
	"""Makes a Flask response with a JSON encoded body"""
	# 此处添加自己定义的 json 格式规则
	if 'message' not in data:
		data = {
			'messsage': 'OK',
			'data': data
		}
	settings = current_app.config.get('RESTFUL_JSON', {})

	# If we're in debug mode, and the indent is not set, we set it to a
	# reasonable value here.  Note that this won't override any existing value
	# that was set.  We also set the "sort_keys" value.
	if current_app.debug:
		settings.setdefault('indent', 4)
		settings.setdefault('sort_keys', not PY3)

	# always end the json dumps with a new line
	# see https://github.com/mitsuhiko/flask/pull/1262
	dumped = dumps(data, **settings) + "\n"

	resp = make_response(dumped, code)
	resp.headers.extend(headers or {})
	return resp
